package org.tiangou.servlet;

import org.tiangou.entity.User;
import org.tiangou.utils.JwtUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/api/main")
public class MainServlet extends BaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取客户端发送过来的token
        // String token = req.getParameter("token");
        String token = req.getHeader("Authorization");

        // 获取payload信息
        String username = JwtUtil.getPayload(token, "username", String.class);

        // 模拟DAO，查询当前登录用户信息
        User user = new User(username, null, "男", 18);

        // 响应客户端
        print(resp, successJson(user));
    }
}
